package com.cj.user.controller;

import com.cj.common.config.handerconfig.IgnoreToken;
import com.cj.common.response.Result;
import com.cj.user.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @Author cheng jun
 * @Description:
 * @Date 2021/7/9 21:54
 */
@Controller
@RequestMapping("/file")
public class FileController {

    @Autowired
    private FileService fileService;

    /**
     * 文件上传
     * @param file
     * @param fileId
     * @return
     */
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    @ResponseBody
    //@IgnoreToken
    public Result upload(/*@RequestHeader(value = "user") String user,*/ @RequestParam("file") MultipartFile file,
                         @RequestParam(value = "fileId") String fileId) {
        return Result.success(fileService.saveFile(file, fileId));
    }

    /**
     * 文件下载
     * @param map
     * @param response
     */
    @RequestMapping(value = "/downLoad", method = RequestMethod.POST)
    public void downLoad(@RequestBody Map<String, Object> map, HttpServletResponse response) {
        fileService.selectFile(map, response);
    }
}
